package com.codegeek.project.slope.domain;

import com.alibaba.fastjson.JSONArray;
import com.codegeek.common.utils.ReplaceIllegalChar;
import com.codegeek.framework.aspectj.lang.annotation.Excel;
import com.codegeek.framework.web.domain.BaseEntity;
import lombok.Data;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Date;
import java.util.List;

/**
 * 监测项对象 slope_monitor_item
 *
 * @author codegeek
 * @date 2020-02-17
 */
@Data
public class SlopeMonitorItem extends BaseEntity {

    public static final Logger logger = LogManager.getLogger("FileUtils");

    private static final long serialVersionUID = 1L;

    /**
     * ID
     */
    private Long itemId;

    /**
     * 名称
     */
    @Excel(name = "名称")
    private String itemName;

    /**
     * 单位
     */
    @Excel(name = "单位")
    private String itemUnit;

    /**
     * 当前值
     */
    @Excel(name = "当前值")
    private Float itemValue;

    /**
     * 当前值上传时间
     */
    @Excel(name = "当前值上传时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date valueTime;

    /**
     * 所属传感器ID
     */
    @Excel(name = "所属传感器ID")
    private Long sensorId;

    /**
     * 所属传感器
     */
    private SlopeSensor sensor;

    /**
     * 阈值1
     */
    @Excel(name = "阈值1")
    private Float threshold1;

    /**
     * 阈值2
     */
    @Excel(name = "阈值2")
    private Float threshold2;

    /**
     * 阈值3
     */
    @Excel(name = "阈值3")
    private Float threshold3;

    /**
     * 搜索关键字
     */
    @Excel(name = "搜索关键字")
    private String keywords;

    /**
     * 阈值类型
     */
    @Excel(name = "阈值类型")
    private Integer thresholdType;

    private Integer sensorType;

    private Integer state;

    private String deviceName;

    static public List<SlopeMonitorItem> parseListFromJsonString(String str) {
        try {
            return JSONArray.parseArray(str, SlopeMonitorItem.class);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e);
            return null;
        }
    }

    public void setItemName(String itemName) {
        this.itemName = new ReplaceIllegalChar().replace(itemName);
    }

    public void setItemUnit(String itemUnit) {
        this.itemUnit = new ReplaceIllegalChar().replace(itemUnit);
    }

    public void setKeywords(String keywords) {
        this.keywords = new ReplaceIllegalChar().replace(keywords);
    }

    public void setDeviceName(String deviceName) {
        this.deviceName = new ReplaceIllegalChar().replace(deviceName);
    }
}
